package com.cyzy.mapper;

import com.cyzy.dto.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MessageMapper {

    @Insert("insert into message (messageid, fromUser, toUserid,toUser, content, sendTime) values (#{messageid}, #{fromUser},#{toUserid}, #{toUser}, #{content}, #{sendTime})")
    public  int insertMessage(Message message);


    @Update("update message set status = #{status} where messageid = #{messageId}")
    void updateMessageStatus(Integer messageId, String status);

    //根据id获取全部
    @Select("select * from message where toUserid = #{toUserid} order by messageId desc")
    public List<Message> getMessageByToUser(Integer toUserid);

    //根据id获取未读
    @Select("select * from message where toUserid = #{toUserid} and isRead = 0 order by messageId desc")
    public List<Message> getMessageByToUserByisRead(Integer toUserid);

    //根据messageid修改isRead
    @Update("update message set isRead = 1 where messageId = #{messageId}")
    public int updateMessageIsRead(Integer messageid);

    //根据id查询信息
    @Select("select * from message where messageId = #{messageId}")
    public Message getMessageById(Integer messageId);
}
